package com.codeduck.demo.simple;

import com.alibaba.fastjson.JSON;
import com.codeduck.constant.KafkaConst;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.PartitionOffset;
import org.springframework.kafka.annotation.TopicPartition;
import org.springframework.stereotype.Service;

/**
 * @author: <a href="mailto:codeduck@163.com">codeduck</a>
 * @date: 2023/01/14
 */
@Service
@Slf4j
public class SimpleConsumer {

    private static final String P0 = "0";
    private static final String[] P1_2 = new String[]{"1", "2"};

    @KafkaListener(groupId = "simple_consumer", topicPartitions = {
            @TopicPartition(topic = KafkaConst.SIMPLE_TOPIC, partitionOffsets = @PartitionOffset(partition = "0", initialOffset = "-1"))})
    public void consumerA(String msg) {
        log.info("consumerA: 获得消息 [{}]", msg);
    }

    @KafkaListener(groupId = "simple_consumer",
            topicPartitions = {
                    @TopicPartition(topic = KafkaConst.SIMPLE_TOPIC, partitionOffsets = @PartitionOffset(partition = "1", initialOffset = "-1")),
                    @TopicPartition(topic = KafkaConst.SIMPLE_TOPIC, partitionOffsets = @PartitionOffset(partition = "2", initialOffset = "-1"))
            })
    public void consumerB(String msg) {
        log.info("consumerB: 获得消息 [{}]", msg);
    }


}
